import { Injectable } from '@nestjs/common';
import { DbService } from '../../db/db.service';
import { UserGroup } from '@app/db/entity/UserGroup';
import * as dayjs from 'dayjs';

@Injectable()
export class UserGroupService {
    constructor(
        private readonly db:DbService,
    ){}

    async options() {
        return this.db.userGroup.find(null, {name: true, id: true}, null, null, {sort : 'DESC', id : 'DESC'})
    }

    async list() {
        return this.db.userGroup.find(null, null, null, null, {sort : 'DESC', id : 'DESC'})
    }

    async add(dto:UserGroup, memberId:number) {
        return this.db.userGroup.insert({createTime: dayjs().unix(), creatorId: memberId, ...dto})
    }

    async update(dto:UserGroup, memberId:number) {
        return this.db.userGroup.update({id: dto.id}, {updateTime: dayjs().unix(), ...dto})
    }

    async del(id:number) {
        return this.db.userGroup.delete({id : id})
    }
}
